var http = require('../../utils/http.js');
var config = require('../../utils/config.js');

Page({
    data: {
        seckillActivities: [],
        picDomain: config.picDomain
    },

    onLoad: function () {
        this.loadSeckillActivities();
    },

    // 加载秒杀活动列表
    loadSeckillActivities: function () {
        wx.showLoading({ title: '加载中...' });
        var params = {
            url: "/seckill-service/seckill/activities",
            method: "GET",
            data: {},
            callBack: (res) => {
                wx.hideLoading();
                console.log(res)
                this.setData({
                    seckillActivities: res
                });
            }
        };
        http.request(params);
    },

    // 跳转到秒杀详情页
    toSeckillDetail: function (e) {
        var activityId = e.currentTarget.dataset.activityid;
        wx.navigateTo({
            url: '/pages/seckill-detail/seckill-detail?activityId=' + activityId
        });
    },

    // 下拉刷新
    onPullDownRefresh: function () {
        this.loadSeckillActivities();
        wx.stopPullDownRefresh();
    }
});